feat(auth): share validation and improve authentication handling #53
+843
−293
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change
Improved the existing authentication flow while keeping the current session-token approach.
INVALID_INPUT,INVALID_CREDENTIALS,EMAIL_TAKEN, andRATE_LIMITED.Added focused tests and documentation in
docs/auth-improvements.md.Scope
This PR focuses on authentication. CRUD work remains separate.
Session tokens remain in localStorage, and existing session restoration and protected routes are preserved. HttpOnly cookies and HTTPS are deferred.
No database migration is required.
Verification
npm run checkpassed, including formatting, linting, generated contracts, migration metadata, TypeScript, 212 tests, and production builds.Tests cover validation boundaries, short existing login passwords, malformed session IDs, session restoration, logout, structured errors, rate limits, and proxy-header handling.
Deployment notes
Set
AUTH_TRUST_PROXY=trueon the VM when using the documented local Apache proxy. The API should continue listening on127.0.0.1.Without this setting, requests through Apache share the same rate-limit bucket. Rate-limit counters are held in memory and reset when the API restarts.
Verify login, registration, refresh, logout, and client-IP forwarding on the VM after deployment.
AI use
AI assisted with implementation, documentation, testing, and code review. Changes were checked with automated tests, type checking, builds, and local startup verification.